package com.zhx.common.user.controller;



import com.zhx.common.common.domain.vo.req.CursorPageBaseReq;
import com.zhx.common.common.domain.vo.req.PageBaseReq;
import com.zhx.common.common.domain.vo.resp.ApiResult;
import com.zhx.common.common.domain.vo.resp.CursorPageBaseResp;
import com.zhx.common.common.domain.vo.resp.PageBaseResp;
import com.zhx.common.common.util.RequestHolder;
import com.zhx.common.user.domain.vo.req.friend.FriendApplyReq;
import com.zhx.common.user.domain.vo.req.friend.FriendApproveReq;
import com.zhx.common.user.domain.vo.req.friend.FriendCheckReq;
import com.zhx.common.user.domain.vo.req.friend.FriendDeleteReq;
import com.zhx.common.user.domain.vo.resp.friend.FriendApplyResp;
import com.zhx.common.user.domain.vo.resp.friend.FriendCheckResp;
import com.zhx.common.user.domain.vo.resp.friend.FriendResp;
import com.zhx.common.user.domain.vo.resp.friend.FriendUnreadResp;
import com.zhx.common.user.service.IUserFriendService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * <p>
 * 用户联系人表 前端控制器
 * </p>
 *
 * @author zhx
 * @since 2024-01-15
 */
@RestController
@RequestMapping("/capi/user/friend")
@Api(tags = "好友相关接口")
@Slf4j
public class FriendController {

    @Resource
    private IUserFriendService friendService;

    @ApiOperation(value = "批量判断是否是自己好友")
    @GetMapping("/check")
    public ApiResult<FriendCheckResp> check(@Valid FriendCheckReq req){
        Long uid = RequestHolder.get().getUid();
        return ApiResult.success(friendService.check(uid,req));
    }

    @PostMapping("/apply")
    @ApiOperation("申请好友")
    public ApiResult<Void> apply(@Valid @RequestBody FriendApplyReq req){
        Long uid = RequestHolder.get().getUid();
        friendService.apply(uid,req);
        return ApiResult.success();
    }
    @DeleteMapping()
    @ApiOperation("删除好友")
    public ApiResult<Void> delete(@Valid @RequestBody FriendDeleteReq req){
        Long uid = RequestHolder.get().getUid();
        friendService.delete(uid,req.getTargetUid());
        return ApiResult.success();
    }

    @GetMapping("apply/page")
    @ApiOperation("好友申请列表")
    public ApiResult<PageBaseResp<FriendApplyResp>> page(@Valid PageBaseReq req){
        Long uid = RequestHolder.get().getUid();
        return ApiResult.success(friendService.pageApplyByFriend(uid,req));
    }

    @GetMapping("/apply/unread")
    @ApiOperation("申请未读数")
    public ApiResult<FriendUnreadResp> unread() {
        Long uid = RequestHolder.get().getUid();
        return ApiResult.success(friendService.unread(uid));
    }

    @PutMapping("/apply")
    @ApiOperation("审批同意")
    public ApiResult<Void> applyApprove(@Valid @RequestBody FriendApproveReq request) {
        friendService.applyApprove(RequestHolder.get().getUid(), request);
        return ApiResult.success();
    }

    @ApiOperation(value = "联系人列表")
    @GetMapping("/page")
    public ApiResult<CursorPageBaseResp<FriendResp>> friendList(@Valid CursorPageBaseReq req){
        Long uid = RequestHolder.get().getUid();
        return ApiResult.success(friendService.friendList(uid, req));
    }

}

